package br.com.qualityempresa.seguranca

class Acesso implements Comparable {

	String controle
	String acao
	String descricao

	static constraints = {
		controle(unique: ['acao'], blank:false, nullable:false, maxSize: 50)
		acao(blank:false, nullable:false, maxSize: 50)
		descricao(blank:true, nullable:true, maxSize: 100)
	}

	public boolean isExpressaoCoincide(String controle, String acao) {
		return (this.controle.equals('*') || this.controle.equals(controle)) && (this.acao.equals('*') || this.acao.equals(acao))
	}
	
	@Override
	public String toString() {
		return "$controle:$acao";
	}

	int compareTo(obj) {
		if (controle.compareTo(obj.controle) == 0) {
			return acao.compareTo(obj.acao)
		} else {
			return controle.compareTo(obj.controle)
		}
	}
}
